package com.qf.staff.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.result.RespResult;
import com.qf.staff.common.qo.DeptQo;
import com.qf.staff.common.vo.DeptVo;
import com.qf.staff.service.DeptSerice;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "部门管理Api")
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Resource
    DeptSerice deptSerice;

    /*
     *
     * */
    @ApiOperation("查询所有部门信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @GetMapping("/list")
    public RespResult<IPage<DeptVo>> list(@RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int size) {
        return RespResult.success(deptSerice.list(page, size));
    }

    @ApiOperation("查询部门下面的员工数")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @ApiImplicitParams({@ApiImplicitParam(name = "deptName", value = "部门名称")})
    @GetMapping("/count/people")
    public RespResult<Integer> countPeople(String deptName) {
        return RespResult.success(deptSerice.count(deptName));
    }

    @ApiOperation("根据id修改status为0是删除部门信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/remove")
    public RespResult<Integer> remove(DeptQo deptQo) {
        return RespResult.success(deptSerice.delete(deptQo));
    }

    @ApiOperation("根据id修改status为0是批量删除部门信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/remove/all/{status}")
    public int removeAll(@RequestBody List<Integer> ids, @PathVariable("status") int status) {
        return deptSerice.deleteAll(ids, status);
    }

    @ApiOperation("根据id修改部门信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id"),
            @ApiImplicitParam(name = "deptName", value = "部门名称"),
            @ApiImplicitParam(name = "status", value = "部门状态")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PutMapping("/modify")
    public RespResult<Integer> modify(DeptQo deptQo) {
        return RespResult.success(deptSerice.modify(deptQo));
    }


    @ApiOperation("增加部门信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id"),
            @ApiImplicitParam(name = "deptName", value = "部门名称"),
            @ApiImplicitParam(name = "status", value = "部门状态")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PostMapping("/add")
    public RespResult<Integer> add(DeptQo deptQo) {
        return RespResult.success(deptSerice.add(deptQo));
    }
}
